package com.ywd.platform.controller;

import com.ywd.platform.dto.VehicleDto;
import com.ywd.platform.page.VehiclePageDto;
import com.ywd.platform.exception.R;
import com.ywd.platform.exception.RPage;
import com.ywd.platform.service.impl.VehicleServiceImpl;
import com.ywd.platform.vo.VehicleVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * YWD
 * 2025/8/17
 */
@AllArgsConstructor
@RestController
@RequestMapping("/vehicle")
@Tag(name = "车辆管理")
public class VehicleController {

    private final VehicleServiceImpl vehicleService;

    @PostMapping("/getVehiclePage")
    @Operation(summary = "查询车辆列表")
    public RPage<List<VehicleVo>> getVehiclePage(@RequestBody VehiclePageDto dto){
        return vehicleService.getVehiclePage(dto);
    }

    @GetMapping("/getVehicleDetails/{id}")
    @Operation(summary = "查询车辆详情")
    public R<VehicleVo> getVehicleDetails(@Schema(description = "车辆ID") @PathVariable("id") Integer id){
        return R.ok(vehicleService.getVehicleDetails(id));
    }

    @PostMapping("/saveVehicle")
    @Operation(summary = "添加车辆")
    public R<Boolean> saveVehicle(@RequestBody VehicleDto dto){
        return R.ok(vehicleService.saveVehicle(dto));
    }

    @PutMapping("/updateVehicle")
    @Operation(summary = "修改车辆")
    public R<Boolean> updateVehicle(@RequestBody VehicleDto dto){
        return R.ok(vehicleService.updateVehicle(dto));
    }

    @DeleteMapping("/deleteVehicle/{id}")
    @Operation(summary = "删除车辆")
    public R<Boolean> deleteVehicle(@Schema(description = "车辆ID") @PathVariable("id") Integer id){
        return R.ok(vehicleService.deleteVehicle(id));
    }

}
